const obj = {
  tag: 'div',
  style: 'text-align: center;',
  children: [
    {
      tag: 'span',
      children: 'hello world',
      style: 'color: red',
    },
  ],
};
function Render(obj, root) {
  const el = document.createElement(obj.tag);
  el.style = obj.style;
  if (typeof obj.children === 'string') {
    const text = document.createTextNode(obj.children);
    el.appendChild(text);
  } else if (obj.children) {
    // 数组,递归调用Render,使用el作为root参数
    obj.children.forEach((child) => Render(child, el));
  }
  root.appendChild(el);
}
Render(obj, document.body);
